package servlet.huwenyao;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import service.OrderService;
import service.impl.OrderServiceImpl;
import util.JsonDateValueProcessor;
import util.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/SeleWareServlet")
public class SeleWareServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //设置返回的格式
        response.setContentType("text/json;charset=UTF-8");
        OrderService orderService=new OrderServiceImpl();
        JSONObject json=new JSONObject();
        json.put("code",0);
        json.put("msg","");
        JsonConfig config=new JsonConfig();
        config.registerJsonValueProcessor(java.util.Date.class, new JsonDateValueProcessor());
        JSONArray array=JSONArray.fromObject(orderService.goodsList(),config);
        json.put("data",array);
        PrintWriter out = response.getWriter();
        out.print(json);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doPost(request,response);
    }
}
